Avorion Script API Documentation

destinationSectorReady
onAIStateChanged
onAllScriptValuesChanged
onAutoSelected
onBlockChanged
onBlockDamaged
onBlockDestroyed
onBlockHealed
onBlockPlanChanged
onBlocksAdded
onBlocksRemove
onBlocksRemoved
onBoardersDefeated
onBoardersLand
onBoardingFight
onBoardingSuccessful
onBreak
onCaptainChanged
onCaptainChanged
onCargoChanged
onCargoLootCollected
onCollision
onCraftSeatEntered
onCraftSeatLeft
onCrewChanged
onCrewChanged
onCrewLootCollected
onDamaged
onDestroyed
onDockedByEntity
onEntityDocked
onEntityUndocked
onFighterAdded
onFighterLanded
onFighterRemove
onFighterRemoved
onFighterStarted
onHealed
onHullHit
onHyperspaceEntered
onHyperspaceEntered
onInventoryItemLootCollected
onJump
onJumpRouteCalculationStarted
onLootCollected
onMaterialLootCollected
onMoneyLootCollected
onPassengerAdded
onPassengerAdded
onPassengerRemoved
onPassengerRemoved
onPassengersRemoved
onPassengersRemoved
onPlanModifiedByBuilding
onScriptAdded
onScriptRemoved
onScriptValueChanged
onSectorEntered
onSelected
onSetForDeletion
onShaftAutomaticLoadingTypeAssign
onShaftWeaponIndexAssign
onShieldActivate
onShieldDamaged
onShieldDeactivate
onShieldHealed
onShieldHit
onShotFired
onShotHit
onSquadAdded
onSquadOrdersChanged
onSquadRemove
onSquadRemoved
onStartDialog
onStartFiring
onStopFiring
onSystemsChanged
onSystemUpgradeLootCollected
onTorpedoAdded
onTorpedoHit
onTorpedoHullHit
onTorpedoLaunched
onTorpedoRemove
onTorpedoRemoved
onTorpedoShieldHit
onTorpedoStorageChanged
onTurretAdded
onTurretDestroyed
onTurretLootCollected
onTurretRemoved
onTurretRemovedByPlayer
onUndockedFromEntity

Entity Callbacks

Note: Callbacks have to be buffered in certain situations and won't happen immediately. When unregistering a callback during a callback, all callbacks that were buffered during the last frame may still be sent, even though they were unregistered.

callback destinationSectorReady(sectorReady)

Executed when the availability state of the destination sector changes. When the sector is loaded into memory, it's set to true. When the sector is unloaded from memory, because there's no player near it, it's set to false.

Parameters

sectorReady Boolean indicating whether the destination sector is in memory

callback onAIStateChanged(entityId, state)

Executed whenever the AI state of the entity changes

Parameters

entityId The id of the entity
state The id of the new state

callback onAllScriptValuesChanged(entityId)

Executed whenever all scripts values of the entity have been changed at once

Parameters

entityId The id of the entity

callback onAutoSelected()

Executed when the entity gets selected by the player on the client.

callback onBlockChanged(objectIndex, blockIndex, changeFlags)

Executed whenever the plan of the entity is changed.

Parameters

objectIndex The id of the entity
blockIndex The index of the block
changeFlags The flags of the block changes

callback onBlockDamaged(objectIndex, blockIndex, inflictorId, damage, damageType)

Executed whenever a block object is damaged in the sector. This callback is executed after the damage is dealt to the block. Don't remove the block in this callback, this will lead to a crash.

Parameters

objectIndex The index of the damaged object
blockIndex The index of the damaged block
inflictorId The id of the entity that inflicted the damage
damage The damage that was inflicted to the entity
damageType The type of damage

callback onBlockDestroyed(objectIndex, index, block, lastDamageInflictor, damageSource)

Executed whenever a block of the block object got destroyed This callback is executed *after* the block was destroyed

Parameters

objectIndex The id of the entity
index Index of the block
block The block (as removed from the plan)
lastDamageInflictor The index of the last entity that inflicted damage to the destroyed block
damageSource The source of damage

callback onBlockHealed(objectIndex, blockIndex, damage)

Executed whenever a block of the entity is healed. Don't remove the block in this callback, this will lead to a crash.

Parameters

objectIndex The index of the healed object
blockIndex The index of the healed block
damage The damage the entity was healed for

callback onBlockPlanChanged(objectIndex, allBlocksChanged)

Executed whenever the plan of the entity is changed.

Parameters

objectIndex The id of the entity
allBlocksChanged A boolean that indicates whether all the blocks in the block plan have potentially changed

callback onBlocksAdded(objectIndex, wasRepaired, blockIndices)

Executed whenever new block are added to the entity. This callback is executed after the blocks were added.

Parameters

objectIndex The id of the entity
wasRepaired true if the callback was fired because of a repair operation, false otherwise
blockIndices The indices of the added blocks, as variable arguments list

callback onBlocksRemove(objectIndex, blockIndices)

Executed whenever a block will be removed from the plan by building (instead of combat). This callback is executed before the block is removed. IMPORTANT! This only fires on blocks that the player directly chose to be removed. Blocks that get removed because they don't have a connection to the root block any more get signalled after removal by 'onBlocksRemoved'.

Parameters

objectIndex The id of the entity
blockIndices The indices of the removed blocks, as variable arguments list

callback onBlocksRemoved(objectIndex, blockIndices)

Executed whenever a block is removed from the plan by building (instead of combat). This callback is executed after the block is removed.

Parameters

objectIndex The id of the entity
blockIndices The indices of the removed blocks, as variable arguments list

callback onBoardersDefeated(entityId, attackingFaction)

Executed whenever all boarders were defeated

Parameters

entityId The id of the entity
attackingFaction The index of the attacking faction

callback onBoardersLand(entityId, attackingFaction, firstLanding)

Executed when boarders land on an entity

Parameters

entityId The id of the entity
attackingFaction The index of the attacking faction
firstLanding True if these are the first boarders, false otherwise

callback onBoardingFight(entityId, attackingFaction)

Executed on every round of fighting with boarders

Parameters

entityId The id of the entity
attackingFaction The index of the attacking faction

callback onBoardingSuccessful(entityId, oldFactionIndex, newFactionIndex)

Executed whenever an entity was boarded successfully

Parameters

entityId The id of the entity
oldFactionIndex The index of the faction that owned the entity before boarding
newFactionIndex The index of the attacking faction that now owns the entity

callback onBreak(objectIndex, plan...)

Executed when the plan of the entity breaks. This callback is executed after the block broke. This callback is expensive, don't register for it if you don't absolutely need it.

Parameters

objectIndex The id of the entity
plan... The plans of the broken off parts

callback onCaptainChanged(index, captain)

Executed whenever the captain of an entity in the sector changes. This callback is executed *after* the captain changed on the entity.

Parameters

index The id of the entity
captain The new captain (nil if none) of the entity

callback onCaptainChanged(index, captain)

Executed whenever the captain of the entity changes. This callback is executed *after* the captain changed on the entity.

Parameters

index The id of the entity
captain The new captain (nil if none) of the entity

callback onCargoChanged(objectIndex, delta, good)

Executed whenever the cargo of an entity in the sector changes. This callback is executed *after* the cargo was changed on the entity.

Parameters

objectIndex The id of the entity
delta The amount of cargo that changed
good The good that changed

callback onCargoLootCollected(collector, lootIndex, amount, good, owner)

Executed whenever trading good loot gets collected by a player

Parameters

collector The id of the entity that collected loot
lootIndex The index of the collected loot
amount The amount of goods that were collected
good The good that was inside the loot entity
owner The original owner of the cargo

callback onCollision(objectIndexA, objectIndexB, damageA, damageB, steererA, steererB)

Executed whenever two block objects collided in the sector

Parameters

objectIndexA The index of the one colliding object
objectIndexB The index of the other colliding object
damageA The damage that is inflicted to object A
damageB The damage that is inflicted to object B
steererA The steerer ID of objectA. When an object is docked, not the object itself but the steerer is the one responsible for collisions
steererB The steerer ID of objectB. When an object is docked, not the object itself but the steerer is the one responsible for collisions

callback onCraftSeatEntered(entityId, seat, playerIndex, firstPlayer)

Executed whenever a player enters an empty craft or the last player exits it

Parameters

entityId The id of the entity
seat The seat index
playerIndex The index of the player that entered the seat
firstPlayer A bool indicating whether the craft's seats were empty before

callback onCraftSeatLeft(entityId, seat, playerIndex, playersRemaining)

Executed whenever a player enters an empty craft or the last player exits it

Parameters

entityId The id of the entity
seat The seat index that was previously occupied
playerIndex The index of the player that left the seat
playersRemaining A bool indicating whether there are still players on the craft

callback onCrewChanged(index, delta, profession)

Executed whenever the crew of an entity in the sector changes. This callback is executed *after* the crew was changed on the entity.

Parameters

index The id of the entity
delta The amount of crewmen that changed
profession The profession of the crew that changed

callback onCrewChanged(index)

Executed whenever the crew of the entity changes. This callback is executed *after* the crew was changed on the entity.

Parameters

index The id of the entity

callback onCrewLootCollected(collector, lootIndex)

Executed whenever trading good loot gets collected by a player

Parameters

collector The id of the entity that collected loot
lootIndex The index of the collected loot

callback onDamaged(objectIndex, amount, inflictor, damageSource, damageType)

Executed whenever an entity is damaged in the sector.

Parameters

objectIndex The index of the damaged object
amount The amount of damage that was dealt
inflictor The id of the entity that dealt the damage
damageSource The source of damage
damageType The type of damage

callback onDestroyed(index, lastDamageInflictor)

Executed when the entity was destroyed

Parameters

index The id of the entity that was destroyed
lastDamageInflictor The index of the last entity that inflicted damage to the destroyed entity

callback onDockedByEntity(dockeeId, dockerId)

Executed whenever this entity was docked to another entity

Parameters

dockeeId The id of the entity that was docked (child)
dockerId The id of the docking entity (parent)

callback onEntityDocked(dockerId, dockeeId)

Executed whenever an entity docks to another entity

Parameters

dockerId The id of the docking entity (parent)
dockeeId The id of the entity that was docked (child)

callback onEntityUndocked(dockerId, dockeeId)

Executed whenever an entity undocks from another entity

Parameters

dockerId The id of the docking entity (parent)
dockeeId The id of the entity that was docked (child)

callback onFighterAdded(entityId, squadIndex, fighterIndex, landed)

Executed whenever a fighter is added to the entity

Parameters

entityId The id of the entity
squadIndex The index of the squad
fighterIndex The index of the fighter in the squad
landed A boolean whether the fighter landed or got added otherwise

callback onFighterLanded(entityId, squadIndex, fighterId)

Executed whenever a fighter starts from a hangar of the entity

Parameters

entityId The id of the entity the fighter landed on
squadIndex The index of the squad
fighterId The id of the fighter that landed

callback onFighterRemove(entityId, squadIndex, fighterIndex, started)

Executed whenever a fighter is removed from the entity, before it gets removed

Parameters

entityId The id of the entity
squadIndex The index of the squad
fighterIndex The index of the fighter in the squad
started A boolean whether the fighter started or got removed otherwise

callback onFighterRemoved(entityId, squadIndex, fighterIndex, started)

Executed whenever a fighter is removed from the entity, after it got removed

Parameters

entityId The id of the entity
squadIndex The index of the squad
fighterIndex The index of the fighter in the squad
started A boolean whether the fighter started or got removed otherwise

callback onFighterStarted(entityId, squadIndex, fighterId)

Executed whenever a fighter starts from a hangar of the entity

Parameters

entityId The id of the entity the fighter started from
squadIndex The index of the squad
fighterId The id of the fighter that started

callback onHealed(objectIndex, amount, inflictor)

Executed whenever an entity is healed in the sector.

Parameters

objectIndex The index of the damaged entity
amount The amount of damage that was healed
inflictor The id of the entity that dealt the damage

callback onHullHit(objectIndex, blockIndex, shooterIndex, damage, location)

Executed whenever a block object is hit by a shot in the sector. Don't delete the block that is hit by the shot, this will lead to a crash.

Parameters

objectIndex The index of the object that got shot at
blockIndex The index of the block that was hit by the shot
shooterIndex The index of the craft that fired the shot
damage The damage the shot dealt to the object
location The impact location

callback onHyperspaceEntered(entityId, dx, dy)

Executed whenever an entity in the sector jumps into hyperspace. Won't be triggered when changing sector through background simulation, death, or gate/wormholes.

Parameters

entityId The id of the entity that was entered hyperspace
dx X coordinate of the destination
dy Y coordinate of the destination

callback onHyperspaceEntered(entityId, dx, dy)

Executed whenever the entity jumps into hyperspace. Won't be triggered when changing sector through background simulation, death, or gate/wormholes.

Parameters

entityId The id of the entity that was entered hyperspace
dx X coordinate of the destination
dy Y coordinate of the destination

callback onInventoryItemLootCollected(collector, lootIndex)

Executed whenever inventory item loot gets collected by

Parameters

collector The id of the entity which collected the loot
lootIndex The index of the loot that was collected

callback onJump(shipId, x, y, sectorChangeType)

Executed whenever the entity jumps into another sector.

Parameters

shipId The id of the entity that will jump
x The x coordinate of the target sector
y The y coordinate of the target sector
sectorChangeType SectorChangeType enum what kind of sector change it is

callback onJumpRouteCalculationStarted(playerIndex, destinationX, destinationY)

Executed whenever a player starts a new hyperspace jump route calculation

Parameters

playerIndex The index of the player starting the calculation
destinationX The x-coordinate of the destination sector
destinationY The y-coordinate of the destination sector

callback onLootCollected(collector, lootIndex)

Executed whenever loot gets collected by anyone, be it player or AI faction

Parameters

collector The id of the entity which collected the loot
lootIndex The index of the collected loot

callback onMaterialLootCollected(collector, lootIndex, materialType, value)

Executed whenever material loot gets collected by

Parameters

collector The id of the entity which collected the loot
lootIndex The index of the loot that was collected
materialType The type of material contained in the loot
value The amount of material the loot contained

callback onMoneyLootCollected(collector, lootIndex, value)

Executed whenever money loot gets collected by the entity

Parameters

collector The id of the entity which collected the loot
lootIndex The index of the collected loot
value The amount of credits the loot contained

callback onPassengerAdded(index, passenger)

Executed whenever a passenger is added to an entity in the sector. This callback is executed *after* the passenger was added.

Parameters

index The id of the entity
passenger The passenger

callback onPassengerAdded(index, passenger)

Executed whenever a passenger is added to the entity. This callback is executed *after* the passenger was added.

Parameters

index The id of the entity
passenger The passenger

callback onPassengerRemoved(index, passenger)

Executed whenever a passenger is removed from an entity in the sector. This callback is executed *after* the passenger was removed.

Parameters

index The id of the entity
passenger The passenger

callback onPassengerRemoved(index, passenger)

Executed whenever a passenger is removed to the entity. This callback is executed *after* the passenger was removed.

Parameters

index The id of the entity
passenger The passenger

callback onPassengersRemoved(index, amount)

Executed whenever passengers are removed from the entity. This callback is executed *after* the passengers were removed.

Parameters

index The id of the entity
amount Amount of removed passengers

callback onPassengersRemoved(index, amount)

Executed whenever passengers from an entity in the sector are removed. This callback is executed *after* the passengers were removed.

Parameters

index The id of the entity
amount Amount of removed passengers

callback onPlanModifiedByBuilding(shipIndex)

Executed whenever the plan of an entity was modified by building, meaning adding or removing blocks.

Parameters

shipIndex The index of the ship

callback onScriptAdded(entityId, scriptIndex, scriptPath)

Executed whenever a script was added to the entity

Parameters

entityId The id of the entity
scriptIndex The index of the new script
scriptPath The path of the new script

callback onScriptRemoved(entityId, oldScriptIndex, scriptPath)

Executed after a script was removed from the entity

Parameters

entityId The id of the entity
oldScriptIndex The old index of the script that was removed
scriptPath The path of the old script

callback onScriptValueChanged(entityId, name, value)

Executed whenever a script value of the entity was changed

Parameters

entityId The id of the entity
name The name of the value
value The new value

callback onSectorEntered(entityId, x, y)

Executed whenever the entity enters a sector.

Parameters

entityId The index of the entity that entered the sector
x Sector X coordinates of the entered sector
y Sector Y coordinates of the entered sector

callback onSelected()

Executed when the entity gets selected by the player on the client.

callback onSetForDeletion(entityId, deletionType)

Executed whenever the entity is to be deleted.

Parameters

entityId The index of the entity that is to be deleted
deletionType The deletion type

callback onShaftAutomaticLoadingTypeAssign(entityId, shaftIndex, type)

Executed whenever the torpedo type that is automatically loaded into a shaft was assigned

Parameters

entityId The id of the entity
shaftIndex The index of the torpedo shaft
type The type of torpedo that now gets automatically loaded

callback onShaftWeaponIndexAssign(entityId, shaftIndex, weaponIndex)

Executed whenever a torpedo shaft was assigned a new weapon index

Parameters

entityId The id of the entity
shaftIndex The index of the new torpedo shaft
weaponIndex The new weapon index of the shaft

callback onShieldActivate(entityId)

Executed whenever the entities shield activates

Parameters

entityId The id of the entity

callback onShieldDamaged(entityId, amount, damageType, inflictorId)

Executed whenever the entities shield is damaged

Parameters

entityId The id of the entity
amount The amount of damage inflicted
damageType The type of damage dealt
inflictorId The id of the entity that inflicted the damage

callback onShieldDeactivate(entityId)

Executed whenever the entities shield deactivates

Parameters

entityId The id of the entity

callback onShieldHealed(entityId, amount)

Executed whenever the entities shield is healed

Parameters

entityId The id of the entity
amount The amount of damage healed

callback onShieldHit(objectIndex, shooterIndex, damage, location)

Executed whenever an object's shield is hit by a shot in the sector.

Parameters

objectIndex The index of the object that got shot at
shooterIndex The index of the craft that fired the shot
damage The damage the shot dealt to the object
location The impact location

callback onShotFired(entityId)

Executed whenever the entity fires a shot

Parameters

entityId The id of the entity (weapon)

callback onShotHit(objectIndex, shooterIndex, location)

Executed whenever a block object is hit by a shot in the sector.

Parameters

objectIndex The index of the object that got shot at
shooterIndex The index of the craft that fired the shot
location The impact location

callback onSquadAdded(entityId, index)

Executed whenever a squad is removed from the entity

Parameters

entityId The id of the entity
index The index of the squad

callback onSquadOrdersChanged(entityId, squadIndex, orders, targetId)

Executed whenever the orders of a squad of the entity change

Parameters

entityId The id of the entity
squadIndex The index of the squad
orders The orders of the squad
targetId The target assigned to the fighters

callback onSquadRemove(entityId, index)

Executed whenever a squad is removed from the entity, before the squad gets removed

Parameters

entityId The id of the entity
index The index of the squad

callback onSquadRemoved(entityId, index)

Executed whenever a squad is removed from the entity, after the squad got removed

Parameters

entityId The id of the entity
index The index of the squad

callback onStartDialog(objectIndex)

Executed when a dialog is started.

Parameters

objectIndex The index of the entity the dialog is started with

callback onStartFiring(entityId)

Executed whenever the entity starts firing

Parameters

entityId The id of the entity (weapon)

callback onStopFiring(entityId)

Executed whenever the entity stops firing

Parameters

entityId The id of the entity (weapon)

callback onSystemsChanged(shipIndex)

Executed whenever the systems of a ship in the sector changed. This callback is executed *after* the system was changed on the entity.

Parameters

shipIndex The index of the ship

callback onSystemUpgradeLootCollected(collector, lootIndex)

Executed whenever system upgrade loot gets collected by

Parameters

collector The id of the entity which collected the loot
lootIndex The index of the loot that was collected

callback onTorpedoAdded(entityId, shaftIndex, torpedoIndex, torpedo)

Executed whenever a torpedo added to the entity

Parameters

entityId The id of the entity
shaftIndex The index of the new torpedo shaft (-1 if storage)
torpedoIndex The index of the torpedo
torpedo The torpedo that's added

callback onTorpedoHit(objectIndex, shooterIndex, torpedoIndex)

Executed whenever a block object is hit by a torpedo in the sector.

Parameters

objectIndex The index of the object that got shot at
shooterIndex The index of the craft that fired the torpedo
torpedoIndex The index of the torpedo that hit the object

callback onTorpedoHullHit(objectIndex, blockIndex, shooterIndex, damage, torpedoIndex)

Executed whenever a block object is hit by a torpedo in the sector. Don't delete the block that is hit by the torpedo, this will lead to a crash.

Parameters

objectIndex The index of the object that got shot at
blockIndex The index of the block that was hit by the torpedo
shooterIndex The index of the craft that fired the torpedo
damage The damage the torpedo dealt to the object
torpedoIndex The index of the torpedo that hit the object

callback onTorpedoLaunched(entityId, torpedoId)

Executed whenever a torpedo was launched from the entity

Parameters

entityId The id of the entity
torpedoId The id of the launched torpedo

callback onTorpedoRemove(entityId, shaftIndex, torpedoIndex)

Executed whenever a torpedo is about to be removed from the entity

Parameters

entityId The id of the entity
shaftIndex The index of the new torpedo shaft (-1 if storage)
torpedoIndex The index of the torpedo

callback onTorpedoRemoved(entityId, shaftIndex, torpedoIndex)

Executed whenever a torpedo was removed from the entity

Parameters

entityId The id of the entity
shaftIndex The index of the new torpedo shaft (-1 if storage)
torpedoIndex The index of the torpedo

callback onTorpedoShieldHit(objectIndex, shooterIndex, damage, torpedoIndex)

Executed whenever an object's shield is hit by a torpedo in the sector.

Parameters

objectIndex The index of the object that got shot at
shooterIndex The index of the craft that fired the torpedo
damage The damage the torpedo dealt to the object
torpedoIndex The index of the torpedo that hit the object

callback onTorpedoStorageChanged(entityId, storage)

Executed whenever the torpedo storage of the entity changed

Parameters

entityId The id of the entity
storage The new amount of storage available

callback onTurretAdded(shipIndex, turretIndex)

Executed whenever a turret of the entity was added

Parameters

shipIndex The id of the entity that turret was attached to
turretIndex The index of the turret

callback onTurretDestroyed(turretIndex, shipIndex, lastDamageInflictor)

Executed whenever a turret of the entity was destroyed

Parameters

turretIndex The index of the turret that was destroyed
shipIndex The id of the entity that turret was attached to
lastDamageInflictor The index of the last entity that inflicted damage to the destroyed entity

callback onTurretLootCollected(collector, lootIndex)

Executed whenever turret loot gets collected by the entity

Parameters

collector The id of the entity which collected the loot
lootIndex The index of the collected loot

callback onTurretRemoved(shipIndex, turretIndex)

Executed whenever a turret of the entity was removed

Parameters

shipIndex The id of the entity that turret was attached to
turretIndex The index of the turret

callback onTurretRemovedByPlayer(shipIndex, turretIndex)

Executed whenever a turret of the entity was removed by the player

Parameters

shipIndex The id of the entity that turret was attached to
turretIndex The index of the turret

callback onUndockedFromEntity(dockeeId, dockerId)

Executed whenever this entity was undocked from another entity

Parameters

dockeeId The id of the entity that was docked (child)
dockerId The id of the docking entity (parent)

Overview
Home Functions Search
Search:

This is the official documentation for the scripting API of Avorion. This documentation is automatically generated and not necessarily complete. Depending on the context in which functions exist, some documentation such as descriptions, return values or variable names or types may be missing.

Work in Progress. Documentation of Avorion Version: 2.5.7 c8e4beec84f7